<template>
	<view class="">
		<view class='margin-bottom-xl'>
			<view class="flex bg-white p-xs mb-sm marign">
				<view class="flex-sub padding-sm margin-xs radius text-right">
					<view @tap="login" class="cu-avatar xl radius " :style="'background-image:url('+userInfo.headPortrait+')'">
					</view>
				</view>
				<view class="flex-treble padding-sm margin-xs radius">
					<!-- <view class="flex">
					 <view class="padding-left">
						 	<button class=" cu-btn">签到</button>
					 </view>
				</view> -->
					<view class='text-bold text-lg padding-top'>
						{{userInfo.userName}}
						<text v-if="isVip" class="cuIcon-vip margin-left-xs text-orange"></text>
					</view>
					<view class="flex padding-top-sm text-sm">
						<!-- <view class=''>
							<text class="text-gray">积分：</text>
							{{currentData.currentjifen}} 分
						</view> class='margin-left'-->
						<view >
							<text class="text-gray">金币：</text>
							{{currentData.currentjinbi}} 个
							<text class="margin-left text-blue" @tap="crash">提现</text>
						</view>
					</view>
				</view>
			</view>

<template v-if="false">
	<!-- !free -->

			<view v-if="isVip" class="padding bg-white text-center padding-top-xs text-red">
				会员到期时间：{{expireTm}}
				<button class="cu-btn bg-orange sm margin-left" @tap="navTo" data-page="pay">立即续费</button>
			</view>

			<view v-else class="bg-gradual-yellow margin-xs">
				<view class="text-center text-bold padding-xs">
					开通会员，全网信息无限看
				</view>
				<view class="flex">
					<view class="flex-sub text-center">
						<view class="bg-white padding-sm" style="width: 38vw;margin:10px auto">
							查看10条信息
							<view class="text-orange text-sm padding-top-xs">
								3元/条，送100积分
							</view>
						</view>
						<view class="">
							<button @tap="recharge(1, 30)" class="cu-btn bg-green" style="position: relative;top:-12px">30 元 充值</button>
						</view>
					</view>
					<view class="flex-sub text-center">
						<view class="bg-white padding-sm" style="position: relative; width: 38vw;margin:10px auto">
							60天会员
							<view class="text-orange text-sm padding-top-xs">
								约0.66元/天
							</view>
							<view class="cu-tag badge">限时抢购</view>
						</view>
						<view class="">
							<button @tap="recharge(4, 39)" class="cu-btn bg-green" style="position: relative;top:-12px">39 元 开通</button>
						</view>
					</view>
				</view>
				<swiper class="text-center" vertical circular autoplay :interval="3000" :duration="1000" style="height: 30px;">
					<swiper-item v-for="(item, idx) in paylog" :key="idx">
						<view class="swiper-item">{{item.text}}</view>
					</swiper-item>
				</swiper>
			</view>
			
			<view @tap="goShare" class="shadow padding-xs bg-red light text-black text-center margin-sm">
				<template v-if="isVip">
					邀请好友赚现金
				</template>
				<template v-else>
					限时免费领取 VIP 会员
				</template>
			</view>
</template>
			<view class='margin-sm radius bg-white'>
				<view class="cu-list grid col-3 no-border">
					<!-- <view class="cu-item" @tap='navTo' data-page="inte">
						<view class="cuIcon-sponsor text-olive"></view>
						<text>获取积分</text>
					</view> -->
					<view class="cu-item" @tap='navTo' data-page="mypub">
						<view class="cuIcon-edit text-red"></view>
						<text>我的发布</text>
					</view>
					<view class="cu-item" @tap='navTo' data-page="car">
						<view class="cuIcon-edit text-red"></view>
						<text>我的车队</text>
					</view>
					<view class="cu-item" @tap='navTo' data-page="history">
						<view class="cuIcon-attention text-green"></view>
						<text>浏览历史</text>
					</view>
					<view class="cu-item" @tap='navTo' data-page="group">
						<view class="cuIcon-group text-green"></view>
						<text>我的团队</text>
					</view>
					<view class="cu-item" @tap='navTo' data-page="coin">
						<view class="cuIcon-list text-yellow"></view>
						<text>金币收益</text>
					</view>
					<!-- <view class="cu-item" @tap='navTo' data-page="record">
						<view class="cuIcon-moneybag text-olive"></view>
						<text>积分记录</text>
					</view> -->
					<view class="cu-item" @tap='navTo' data-page="intepage">
						<view class="cuIcon-friendadd text-red"></view>
						<text>推荐朋友</text>
					</view>
					<view class="cu-item" @tap='navTo' data-page="set">
						<view class="cuIcon-settings text-green"></view>
						<text>设置</text>
					</view>
					 <!-- <view class="cu-item" @tap='navTo' data-page="more">
						<view class="cuIcon-info text-orange"></view>
						<text>更多信息</text>
					</view> --> 
				</view>
			</view>
		</view>
		
		<view class="cu-modal" :class="showModal?'show':''">
			<view class="cu-dialog" style="height:100vh;width:100vw;background-color: rgba(0,0,0,0.6);">
				<view class="text-right padding">
					<image src="../../static/arrow.png" style="width: 50px;height: 62px;"></image>
				</view>
				<view class="text-white text-left padding text-xl">
					<view class="">
						1、点击右上角 ... 按钮
					</view>
					<view class="padding-top-sm">
						2、点击发给好友，或分享到朋友圈
					</view>
					<view class="padding-top-sm">
						<template v-if="isVip">
							3、好友点击注册、充值后，您即可获得对应的金币（可提现）收益
						</template>
						<template v-else>
							3、好友点击进入、注册后，即可获得一定时间会员服务
						</template>
					</view>
					<view class="padding text-center margin-top">
						<button @tap="showModal = false" class="bg-green">确 定</button>
					</view>
				</view>
			</view>
		</view>
		
		<view class="cu-modal" :class="appModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">{{ isVip?'邀请好友赚金币':'限时领取VIP会员' }}</view>
					<view class="action" @tap="appModal = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					{{ isVip?'点击发给朋友或分享到朋友圈，新好友注册、即送他18积分和五个金币，对方充值后，你可获得对应比例金币（可以提现）收益，另外他邀请的好友充值，你也有收益哦！平台每天更新大量招聘求职信息，帮助卡友找到工作的同时，还能赚点零花钱，还在等什么，赶快行动吧！！！':'点击发给朋友或分享到朋友圈，好友进入、注册后即可获得一定时间会员服务，同时好友也能获得18积分和5个金币，快来分享吧！！' }}
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class=" cu-btn bg-green margin-left" @tap="appShare">
							{{ isVip ? '立即邀请' : '立即分享' }}
						</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {location} from '../../utils/util.js'
	export default {
		data() {
			return {
				free: false,
				expireTm: '',
				currentData: {
					currentjifen: 0,
					currentjinbi: 0
				},
				userInfo: {
					headPortrait: "https://images.51zubus.com/index/f9d1548945bd39a3dab373ad03333b8.jpg",
					identitySeq: '---',
					userName: '游客',
				},
				isVip: false,
				paylog: [],
				showModal: false,
				appModal: false
			}
		},
		onLoad(option) {
		},
		
		onShow() {
			let u = uni.getStorageSync('ONLINE_USER');
			if (u) {
				this.userInfo = u;
				let _this = this;
				uni.showLoading({
					mask: true
				})
				this.baseRequest('api/user/' + u.userID, 'GET', {}, function(res, info) {
					uni.hideLoading();
					// 判断会员
					if (res.expireTm) {
						// let expireTm = Date.parse(new Date(res.expireTm.replace(/-/g, '/')));
						// let now = Date.parse(new Date());
						_this.expireTm = res.expireTm;
						_this.isVip = true;
					} else {
						_this.isVip = false;
						_this.getPaylog();
					}
					_this.log();
				});
				
				//
				let host = window.location.protocol + "//" + window.location.host;
				let str = host + "/pages/user/inteuser2?id="
				str += u.invitCode;
				let data = {
					title: '【镖掌柜-专招驾驶员】强烈推荐！', // 分享标题
					desc: '致力于为全国驾驶员、车主提供招聘求职服务，每天更新大量招聘求职信息。', // 分享描述
					link: str
				}
				this.$wx.wxShare(data); // 设置分享信息
			}
			this.getCurrentUserData();
			//this.getConfig();
		},
		methods: {
			getConfig(){
				let config = uni.getStorageSync('config')
				if(config){
					if(1 == config.freeAncInfo){
						this.free = true
					}
				}
			},
			log(){
				// 记录活跃和定位信息
				let data = location();
				let _this = this;
				this.baseRequest('api/dau/log', 'GET', {}, function(res, info) {
					_this.baseRequest('api/dau/log/user', 'POST', {areaName: data.attenCity, address: data.address}, function(res, info) {
					}, function(){});
				}, function(){});
			},
			goShare(){
				if(typeof androlua == "undefined"){
					this.showModal = true
				}else{
					this.appModal = true
				}
			},
			appShare(){
				let host = window.location.protocol+"//"+window.location.host;
				let str = host + "/pages/user/inteuser2?id="
				let uInfon = uni.getStorageSync('ONLINE_USER');
				str += uInfon.invitCode;
				let arr = [str, '致力于为全国驾驶员、车主提供招聘求职服务，每天更新大量招聘求职信息。', '【镖掌柜-专招驾驶员】强烈推荐！'];
				androlua.pageGoShare(arr);
			},
			// 会员充值
			recharge(paycheckId, paycheckNum) {
				let type = '0';
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == 'micromessenger') {
					type = '1';
				}
				let data = {
					paycheckNum,
					paycheckId,
					type: type
				};
				let _this = this;
				this.baseRequest('api/driver/recharge/gold', 'POST', data, function(res, info) {
					var ua = window.navigator.userAgent.toLowerCase();
					if (ua.match(/micromessenger/i) == 'micromessenger') {
						// 支付
						_this.$wx.wxpay(res, function(r) {
							if (r.errMsg == 'chooseWXPay:ok') {
								window.location.href = res.mweb_url;
							} else {

							}
						});
					} else {
						window.location.href = res.mweb_url;
					}
				});
			},
			getCurrentUserData() {
				let _this = this;
				this.baseRequest('api/getCurrentUserData', 'GET', {}, function(res, info) {
					_this.currentData = res
				});
			},
			login() {
				uni.reLaunch({
					url: '/pages/login/login'
				});
			},
			navTo(e) {
				let page = e.currentTarget.dataset.page;
				uni.navigateTo({
					url: '/pages/user/' + page
				});
			},
			getUserInfo: function() {
				let that = this;
				uni.getStorage({
					key: 'ONLINE_USER',
					success: function(res) {
						that.userInfo = res.data
					}
				});
			},
			NavChange: function(page) {
				uni.navigateTo({
					url: page
				})
			},
			// 获取充值列表
			getPaylog() {
				let _this = this;
				this.baseRequest('api/driver/vip/paylog', 'GET', {}, function(res, info) {
					_this.paylog = res;
				});
			},
			// 提现
			crash() {
				uni.navigateTo({
					url: '/pages/user/crash?currentCreditNum=' + this.currentData.currentjinbi,
				});
				return;


				if (this.currentCreditNum < 50) {
					uni.showModal({
						title: '提示',
						content: '不满50金币不能提现，成为合伙人邀请好友获得金币',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/user/intepage'
								})
							} else if (res.cancel) {}
						}
					});
					return;
				}
				uni.navigateTo({
					url: '/pages/user/crash?currentCreditNum=' + this.currentCreditNum,
				});
			}
		}
	}
</script>
